<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>

<div class="pageContent">
	<form:form method="post" modelAttribute="pro" action="../products/add" cssClass="pageForm required-validate"
enctype="multipart/form-data" onsubmit="return iframeCallback(this, navTabAjaxDone);">
		<div class="pageFormContent" layoutH="56">
			<p>
				<label>大 类：</label>
				<form:select path="type2.type1.t1Id" id="type1" cssClass="required">
					<option value="">请选择</option>
					<form:options items="${list}" itemLabel="name" itemValue="t1Id"/>
				</form:select>
			</p>
			<p>
				<label>小 类：</label>
				<select name="type2.t2Id" id="type2" class="required">
					<option value="">请选择</option>
				</select>
			</p>
			<p>
				<label>型 号：</label>
				<input name="proCode" class="required" type="text" size="30" value="A3586"/>
			</p>
			<p>
				<label>产品名称：</label>
				<input name="proName" class="required" type="text" size="30" value="好大的挖"/>
			</p>
			<p>
				<label>重 量：</label>
				<input name="weight" type="text" size="30" value="1200KG"/>
			</p>
			<p>
				<label>斗 容：</label>
				<input name="douRong" type="text" size="30" value="3立方"/>
			</p>
			<p>
				<label>功 率：</label>
				<input name="pw" type="text" size="30" value="1200KW"/>
			</p>
			<p>
				<label>扭 距：</label>
				<input name="niuJv" type="text" size="30" value="12m"/>
			</p>
			<p>
				<label>排 量：</label>
				<input name="pai" type="text" size="30" value="15L"/>
			</p>
			<p>
				<label>速  度：</label>
				<input name="speed" type="text" size="30" value="5KM/h"/>
			</p>
			<p>
				<label>图 片：</label>
				<input name="file" type="file" class="required" onchange="selImage(this)"/>
				
			</p>
			<p style="height:200px;">
				<img alt="" id="img" src="" height="200px">
			</p>
			<div class="divider"></div>
			<p>
				<label>创建日期：</label>
				<input value="<%=new java.util.Date().toLocaleString() %>" readonly="readonly" type="text" size="30" />
			</p>
			<p>
				<label>创建人员：</label>
				<input readonly="readonly" type="text" size="30" value="${currentUser.truename}"/>
			</p>
			<p>
				<label>最新修改时间：</label>
				<input value="<%=new java.util.Date().toLocaleString() %>" readonly="readonly" type="text" size="30"/>
			</p>
			<p>
				<label>最新修改人员：</label>
				<input readonly="readonly" type="text" size="30" value="${currentUser.truename}"/>
			</p>
		</div>
		<div class="formBar">
			<ul>
				<!--<li><a class="buttonActive" href="javascript:;"><span>保存</span></a></li>-->
				<li><div class="buttonActive"><div class="buttonContent"><button type="submit">保存</button></div></div></li>
				<li>
					<div class="button"><div class="buttonContent"><button type="button" class="close">取消</button></div></div>
				</li>
			</ul>
		</div>
	</form:form>
</div>

<script>
	$(function(){
		var type1 = $("#type1");
		var type2 = $("#type2");
		type1.change(function(){
			type2.loadUrl("../products/findByType1", {"t1Id":type1.val()});
		});
	});
</script>

<script type="text/javascript">
	function selImage(o) {
		document.getElementById("img").src = getFullPath(o);
	}

	function getFullPath(node){
	 var imgURL = "";
	    try{
	        var file = null;
	        if(node.files && node.files[0] ){
	            file = node.files[0];
	        }else if(node.files && node.files.item(0)) {
	            file = node.files.item(0);
	        }
	        //Firefox 因安全性问题已无法直接通过input[file].value 获取完整的文件路径
	        try{
	            //Firefox7.0
	            imgURL =  file.getAsDataURL();
	            //alert("//Firefox7.0"+imgRUL);
	        }catch(e){
	            //Firefox8.0以上
	            imgURL = window.URL.createObjectURL(file);
	            //alert("//Firefox8.0以上"+imgRUL);
	        }
	    }catch(e){      
	        //支持html5的浏览器,比如高版本的firefox、chrome、ie10
	        if (node.files && node.files[0]) {
	            var reader = new FileReader();
	            reader.onload = function (e) {
	                imgURL = e.target.result;
	            };
	            reader.readAsDataURL(node.files[0]);
	        }
	    }
	    return imgURL;
	}
</script>
    